package a10_动态规划;

import java.util.Scanner;

/**
 * <p>
 * a18_完全背包理论基础复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/3/12
 */
public class a18_完全背包理论基础复习3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int num = scanner.nextInt();
        int maxWeight = scanner.nextInt();

        int[] weight = new int[num];
        int[] value = new int[num];

        for (int i = 0; i < num; i++) {
            weight[i] = scanner.nextInt();
            value[i] = scanner.nextInt();
        }

        //dp[i][j]：用0~i个物品装满容量为j的背包的最大价值

        //递推公式
        //不装i：dp[i-1][j]
        //装i：dp[i][j-weight[i]] + value[i]

        //单个数组的话
        //不装i：dp[j]
        //装i：dp[j-weight] + value[i]

        //容量遍历顺序：顺时针
        //dp[i][j] = Math.max(dp[i-1][j],dp[i][j-weight[i]] + value[i]) 需要计算出当前行的前几个

        int[] dp = new int[maxWeight+1];
        for (int i = 0; i < weight.length; i++) {
            for (int j = 0; j <= maxWeight; j++) {
                if(j >= weight[i]){
                    dp[j] = Math.max(dp[j],dp[j-weight[i]] + value[i]);
                }
            }
        }
        System.out.println(dp[maxWeight]);
    }
}
